﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WordNet.Core.ElementContracts;
using WordNet.Core.Extensions;

namespace WordNet.Core
{
    public class SenseEntry: ISenseEntry
    {
        private readonly int _offset;
        private readonly int _num;
        private readonly int _count;
        private readonly ISenseKey _key;

        public SenseEntry(ISenseKey key, int offset, int num, int count)
        {
            if (key == null)
                throw new ArgumentNullException();
            offset.CheckOffset();

            _key = key;
            _offset = offset;
            _num = num;
            _count = count;
        }
        
        public ISenseKey SenseKey
        {
            get { return _key; }
        }

        public int Offset
        {
            get { return _offset; }
        }

        public int SenseNumber
        {
            get { return _num; }
        }

        public int TagCount
        {
            get { return _count; }
        }
        
        public POS PartOfSpeech
        {
            get { return _key.PartOfSpeech; }
        }

        public override int GetHashCode()
        {
            const int prime = 31;
            int result = 1;
            result = prime * result + _count;
            result = prime * result + _key.GetHashCode();
            result = prime * result + _num;
            result = prime * result + _offset;
            return result;
        }

        public override bool Equals(Object obj)
        {
            if (Object.ReferenceEquals(obj, null))
                return false;
            if (Object.ReferenceEquals(this, obj))
                return true;
            ISenseEntry other = obj as ISenseEntry;
            if(other == null)
                return false;
            
            if (_count != other.TagCount)
                return false;
            if (_num != other.SenseNumber)
                return false;
            if (_offset != other.Offset)
                return false;
            if (!_key.Equals(other.SenseKey))
                return false;
            return true;
        }
    }
}
